package main

import (
	"fmt"
	log "github.com/Sirupsen/logrus"
	"os"
	"strings"
	"wzpsoso.com/pushdocker/pushdocker/third-demo/container"
)

//func Run(tty bool, comArray []string, res *subsystems.ResourceConfig) {
func Run(tty bool, comArray []string) {
	fmt.Println(comArray)
	parent, writePipe := container.NewParentProcess(tty)
	if parent == nil {
		log.Errorf("New parent process error")
		return
	}
	if err := parent.Start(); err != nil {
		log.Error(err)
	}

	// use as a cgroup name
	//cgroupManger := cgroups.NewCgroupManager("pushdocker")

	//defer cgroupManger.Destory()

	//cgroupManger.Set(res)
	//cgroupManger.Apply(parent.Process.Pid)
	sendInitCommand(comArray, writePipe)
	parent.Wait()
	os.Exit(0)

}

func sendInitCommand(comArray []string, writePipe *os.File) {
	command := strings.Join(comArray, " ")
	log.Infof("command all is %s", command)
	writePipe.WriteString(command)
	writePipe.Close()
}
